package com.sixth.stock.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sixth.core.entity.Provider;
import com.sixth.core.vo.R;
import com.sixth.stock.service.ProviderService;
import com.sixth.stock.vo.ProviderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@Api(tags = "供应商管理")
@RestController
@RequestMapping("stock/provider")
public class ProviderController {
    @Resource
    private ProviderService providerService;
    @ApiOperation(value = "分页查询供应商")
    @PostMapping("/list")
    public R<IPage<Provider>> selectByPage(@RequestBody ProviderVo providerVo){
        return providerService.selectByPage(providerVo);
    }
    @GetMapping("/init")
    @ApiOperation(value = "初始化查询供应商")
    public R<IPage<Provider>> init(){
        return providerService.selectInit();
    }
    //根据id查询
    @ApiOperation(value = "根据id查询供应商")
    @GetMapping("/getProvider/{id}")
    public R<Provider> getProvider(@PathVariable Long id){
        return providerService.getProvider(id);
    }
    //查询所有可用未删除的供应商，用于下拉框
    @ApiOperation(value = "查询所有可用未删除的供应商", notes = "用于下拉框")
    @GetMapping("/listProvider")
    public R<List<Provider>> listProvider(){
        return providerService.listProvider();
    }
    //修改
    @ApiOperation(value = "修改供应商")
    @PutMapping("/update")
    public R update(@RequestBody Provider provider){
        return providerService.update(provider);
    }
    //添加
    @ApiOperation(value = "添加供应商")
    @PostMapping("/add")
    public R add(@RequestBody Provider provider){
        return providerService.add(provider);
    }
    //删除单个
    @ApiOperation(value = "删除单个供应商")
    @DeleteMapping("/deleteOne/{id}")
    public R delete(@PathVariable Long id){
        return providerService.deleteOne(id);
    }
    //批量删除
    @ApiOperation(value = "批量删除供应商")
    @PostMapping("/batchDelete")
    public R batchDelete(@RequestBody Long[] ids){
        return providerService.batchDelete(ids);
    }
}
